﻿using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using ISSMoviePlex.DAL.Models;
using ISSMoviePlex.DAL.Repositories;

namespace ISSMoviePlex.BLL
{
    public class MovieBLL
    {
        private readonly MovieRepository _movieRepository;

        public MovieBLL()
        {
            _movieRepository = MovieRepository.Instance;
            _movieRepository.Initialize();
        }

        public Movie SearchFirstMovieByTitle(string title)
        {
            return _movieRepository.FindFirstMovieByTitle(title);
        }

        public IEnumerable<Movie> SearchMovieByTitle(string title)
        {
            return _movieRepository.FindMoviesByTitle(title);
        }

        public IEnumerable<Movie> GetAllMovies()
        {
            return _movieRepository.GetAll().ToList();
        }

        public Movie GetMovie(int movieId)
        {
            return _movieRepository.FindById(movieId);
        }

        public void AddMovie(Movie movie)
        {
            _movieRepository.Add(movie);
            _movieRepository.Save();
        }

        public void UpdateMovie(Movie movie)
        {
            _movieRepository.Edit(movie);
            _movieRepository.Save();
        }

        public void DeleteMovie(Movie movie)
        {
            _movieRepository.Delete(movie);
            _movieRepository.Save();
        }

        public IEnumerable<Movie> GetMovieByGenre(string genre)
        {
            return _movieRepository.GetAllMoviesByGenre(genre);
        }
    }
}
